Skip to content

togl: fix crash on startup under Wayland - #493

Open
Opvolger wants to merge 1 commit into
nillerusr:masterfrom
Opvolger:feature/fix-wayland
Open

Opvolger wants to merge 1 commit into
nillerusr:masterfrom
Opvolger:feature/fix-wayland

Conversation

@Opvolger

@Opvolger Opvolger commented Nov 7, 2026

Copy link
Copy Markdown

On Linux with SDL's Wayland video driver, the game crashes with a segmentation fault right after SDL video target is 'wayland'. This is the crash reported in #395 (and mentioned in #393). Until now the only workaround was SDL_VIDEODRIVER=x11.

Cause

CheckOpenGLExtension_internal() in togl/linuxwin/glentrypoints.cpp falls back to glXQueryExtensionsString(glXGetCurrentDisplay(), 0) when an extension is not in GL_EXTENSIONS. Under Wayland, SDL creates the context with EGL, so there is no GLX context. The GLX entry points returned via SDL_GL_GetProcAddress cannot be used there, and their result was passed straight to strstr(), which crashed.

Fix

  • Query the GLX extension string only when SDL's current video driver is x11. SDL_GetCurrentVideoDriver is looked up once with dlsym, because togl does not link against SDL. If it cannot be found, the old behaviour is kept.
  • Skip a NULL display or a NULL extension string instead of passing it to strstr().

Nothing changes for X11 (including XWayland), where the GLX fallback still runs.

Testing

Fedora 44 x86_64, KDE Plasma 6 on Wayland, Intel Arc B390 (Mesa 26.2), timedemo on a d1_canals_01 demo:

Build SDL_VIDEODRIVER=wayland SDL_VIDEODRIVER=x11
master segmentation fault at startup works
this PR works works

The same fix has also been in use on a riscv64 board (Milk-V Jupiter, Debian 13, KDE Plasma on Wayland). RISC-V support itself will be a separate PR.

How this was made

I made this together with Claude Code, Anthropic's AI coding assistant. I guided it throughout and kept the change small and limited to the one function that crashed. I tested the result myself on the machines listed above.

When an extension is not listed in GL_EXTENSIONS, CheckOpenGLExtension
falls back to glXQueryExtensionsString(glXGetCurrentDisplay()). Under
Wayland SDL uses EGL: there is no GLX context and the GLX entry points
returned via SDL_GL_GetProcAddress are unusable stubs, so the result was
passed to strstr() and crashed.

Only query GLX extensions when SDL's current video driver is x11 (looked
up with dlsym, since togl does not link SDL), and skip NULL results.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant